package com.twu.biblioteca.session;

public enum SessionOption {

    LIST_BOOK("1", "List All Books", false),
    CHECKOUT_BOOK("2", "Checkout Book",true),
    RETURN_BOOK("3", "Return Book",true),
    LIST_MOVIE("4", "List All Movies",false),
    CHECKOUT_MOVIE("5", "Checkout Movie",true),
    RETURN_MOVIE("6", "Return Movie",true),
    VIEW_DETAILS("7", "View Your Details",true),
    LOGIN("L", "Login",false),
    QUIT("Quit", "Quit Application",false);

    private final String key;
    private final String text;
    private final boolean needLogin;

    private SessionOption(String key, String text, boolean needLogin) {
        this.key = key;
        this.text = text;
        this.needLogin = needLogin;
    }

    public String getKey() {
        return key;
    }

    public static String getOptionListAsString(boolean loggedIn) {
        String output = "";

        for (SessionOption option : values()) {
            if(option.isNeedLogin() == loggedIn || !option.isNeedLogin())
                output += option.getKey() + ": " + option.getText() + "\n";
        }
        return output;
    }

    private String getText() {
        return text;
    }

    public boolean isNeedLogin() {
        return needLogin;
    }
}
